package main

import (
	"fmt"
	"html/template"
	"net/http"
)

func sayHello(w http.ResponseWriter,r *http.Request)  {
	t, err := template.New("test.tmpl").Funcs(template.FuncMap{
		"trust": func(s string) template.HTML {
			return template.HTML(s)
		},
	}).ParseFiles("./test.tmpl")
	if err != nil {
		fmt.Printf("parse file failed err := %v",err)
	}
	m := map[string]interface{}{
		"msg":"<script>alert('张三撺掇着李四去王五家打了赵六')</script>",
		"a": "<a href='https://blog.csdn.net/weixin_52025712'>本人博客</a>",
	}
	err = t.Execute(w, m)
	if err != nil {
		fmt.Printf("execute file failed err := %v",err)
	}

}

func main() {
	http.HandleFunc("/",sayHello)
	err := http.ListenAndServe(":9000", nil)
	if err != nil {
		fmt.Printf("listen address failed err = %v",err)
	}
}
